home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3170 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.9 KB  |  97 lines

  1. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  2. Path: ERA.COM!era!spencer
  3. From: spencer@ERA.COM (Spencer Allain)
  4. Subject: Re: Hungarian notation
  5. In-Reply-To: c2a192@ugrad.cs.ubc.ca's message of 21 Jan 1996 10: 02:24 -0800
  6. Message-ID: <SPENCER.96Jan22113215@zorgon.ERA.COM>
  7. Sender: news@ERA.COM
  8. Organization: Engineering Research Associates, Vienna, VA
  9. References: <30C40F77.53B5@swsbbs.com> <4cvu68$2jb@macaw.cyberport.com>
  10.     <4d21og$iab@news.xmission.com> <4d2ok0$69s@beach.and.nl>
  11.     <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca>
  12. Date: Mon, 22 Jan 1996 16:32:15 GMT
  13.  
  14. In article <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca> c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
  15.  
  16. > Typedef-like constructs are useful in poorly thought-out languages
  17. > like Modula or Pascal, whose compilers can typically perform
  18. > typechecks based only on name equivalence. That is to say, if I
  19. > declare two types that are both integers, the compiler will say that
  20. > the two types are not equivalent, because it goes only as far as to
  21. > check the name. This is a cop out which simplifies doing one of the
  22. > more difficult phases of compiler construction, which is type
  23. > checking. It has nothing to do with implementing "domains", and
  24. > everything to do with lazy compiler construction. Real compilers will
  25. > detect structure equivalence between types so that you don't have to
  26. > obfuscate your code with confusing type names.  To implement domains,
  27. > just lobotomize the compiler by removing the structure equivalence
  28. > checking so that size_t and time_t become incompatible types.
  29.  
  30. Ok.  I promised myself I was going to stay out of this thread, but I
  31. can't let a statement like this go unheeded.
  32.  
  33. I'm not going to argue about the design of Modula and Pascal, as that
  34. would be like discussing K&R C.  I will note however, that Modula-3 is
  35. a successor to that lineage and it has true structural equivalence,
  36. not a named equivalence type checking system like C++.
  37.  
  38. It is incorrect to say that a 'char' (of size 1 byte on many systems)
  39. and an 'int' (of size 4 bytes on many systems) is structurally
  40. equivalent, yet I must be able to compile this without errors:
  41. (warnings are _not_ errors -- though I get none compiling this anyway)
  42.  
  43.    char a;
  44.    int b;
  45.  
  46.    int main()
  47.    {
  48.      b = -154267 ;
  49.      a = b ;
  50.      return 0 ;
  51.    }
  52.  
  53. Also, even though structurally equivalent, a C compiler must complain
  54. that 'theta = beta' is illegal due to incompatible types.
  55.  
  56.    struct {int k;} alpha, beta ;
  57.    struct {int k;} theta ;
  58.  
  59.    int main()
  60.    {
  61.      alpha.k = 1 ;
  62.      beta = alpha ;
  63.      theta = beta ;
  64.      return 0 ;
  65.    }
  66.  
  67. I know that it sounds as though I'm bashing C, but I'm just trying to
  68. point out some of the restrictions that cannot be completely lifted
  69. regardless of how good a compiler you use.  Warnings can help, such
  70. as the one where some C++ compilers warn when you make comparisons
  71. between signed and unsigned types (which is a senseless comparison,
  72. but is allowed mostly because there aren't true subtypes, but that
  73. is another issue).
  74.  
  75. If you wish to examine more how Modula-3 does its structural
  76. equivalence, and also how it allows reference and object types to be
  77. "BRANDED" so as to guaranteed non-equivalence with other structurally
  78. equivalent but conceptually different types check out:
  79.  
  80.   http://www.research.digital.com/SRC/modula-3/html/home.html
  81.  
  82. specifically the online definition of the language:
  83.  
  84.   http://www.research.digital.com/SRC/m3defn/html/m3.html
  85.  
  86. -Spencer
  87.  
  88. ----------------------------------------------------------------------
  89. Spencer Allain                    E-mail:  spencer@era.com
  90. Engineering Research Associates   Phone :  (703) 734-8800 x1414
  91. 1595 Spring Hill Road             Fax   :  (703) 827-9411
  92. Vienna, VA  22182-2235
  93.  
  94. Modula-3  FAQ                     http://www.vlsi.polymtl.ca/m3/
  95. <A HREF=http://www.vlsi.polymtl.ca/m3/>Modula-3 FAQ, etc. </A>
  96. ----------------------------------------------------------------------
  97.